//
//  AppDelegate.swift
//  BTE
//
//  Created by Mike Zhang on 2025/8/5.
//



//
//
//https://codesign.qq.com/s/576029892464139
//
//对接口前必看-流程文档: https://pwdgtjoqfr.feishu.cn/docx/PYMwdLwDwoey7pxH5fJcC0tlnRe
//文档地址：https://doc.alta-dg.mx/id_pinjaman_instan_ios/index.html
//文档反转义地址：https://doc.alta-dg.mx/decode.php?project=id_pinjaman_instan_ios
//接口访问地址：http://149.129.233.8:6075/Slavicize
//
//测试账号：9111111111（小卡、产品列表、订单列表。 ！！注意！！- 走认证项流程重新登个号）
//测试验证码：241234






import UIKit
import IQKeyboardManagerSwift


@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    
    var launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        
        if #available(iOS 13.0, *) {
            UIApplication.shared.connectedScenes
                .compactMap { $0 as? UIWindowScene }
                .flatMap { $0.windows }
                .forEach { window in
                    window.overrideUserInterfaceStyle = .light
                }
        }
        
        self.launchOptions = launchOptions
        
        initwindow()

        inittodoing()
        
        iqte()
        
        return true
    }

}


fileprivate
extension AppDelegate {
    
    func iqte(){
        IQKeyboardManager.shared.keyboardDistance = 30
        IQKeyboardManager.shared.resignOnTouchOutside = true
        IQKeyboardManager.shared.isEnabled = true
    }
    
    func initwindow(){
        window = UIWindow.init(frame: UIScreen.main.bounds)
        window?.rootViewController = BTELunchViewController()
        window?.makeKeyAndVisible()
    }
    
    
    func inittodoing(){
       
        
        // stva
        DispatchQueue.main.asyncAfter(deadline: .now()+3){
            BTEDeviceIdentifierManager.shared.requestTrackingAuthorizationIfNeeded { response in
                if response {
                    BTEDeviceIdentifierManager.storeVendorIDIfNeeded()
                    BTEDeviceIdentifierManager.shared.uploadIDVA()
                }
            }
        }
     
        
        // location
        LocationService.shared.requestLocationInfo { result in
            switch result {
            case .success((_, let info)):
                LocationUploader.upload(info)
            case .failure(let error):
                print("获取定位失败: \(error)")
            }
        }
        
        // deviceinfo
        DeviceInfoCollector.collectSummary { info in
            DeviceInfoCollector.uploadInfomation(info)
        }

    }
    
}

